package com.lazypeople.domain;

import java.io.File;
import java.util.UUID;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class DownloadTask implements DownloadInfo {
    private String url;
    private File saveFile;
    private int threadCount;
    private String taskId;
    private final DoubleProperty progress = new SimpleDoubleProperty(0.0);
    private static final Logger logger = LoggerFactory.getLogger(DownloadTask.class);

    public DownloadTask() {
        this(null);
    }

    public DownloadTask(String url) {
        this(url, null, 4);
    }

    public DownloadTask(String url, File saveFile) {
        this(url, saveFile, 4);
    }

    public DownloadTask(String url, File saveFile, int threadCount) {
        this.taskId = UUID.randomUUID().toString();
        this.url = url;
        this.saveFile = saveFile;
        this.threadCount = threadCount;
    }

    // 进度属性访问器
    public float getProgress() {
        return (float) progress.get();
    }

    public DoubleProperty progressProperty() {
        return progress;
    }

    public void setProgress(double progress) {
        this.progress.set(progress);
        logger.info("Task {} internal progress set to {}", taskId, progress);
    }

    public String getUrl() {
        return this.url;
    }

    public File getSaveFile() {
        return this.saveFile;
    }

    public int getThreadCount() {
        return this.threadCount;
    }

    public String getTaskId() {
        return this.taskId; // 假设taskId是类的成员变量
    }

}
